package com.example.administrator.nl.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.example.administrator.nl.MainActivity;
import com.example.administrator.nl.R;
import com.hjq.permissions.OnPermission;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;

import java.util.List;

public class StartPageActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start_page);

        // 权限申请
        XXPermissions.with(StartPageActivity.this)
                // 可设置被拒绝后继续申请，直到用户授权或者拒绝
                .constantRequest()
                //支持多个权限组进行请求，不指定则默以清单文件中的危险权限进行请求
                // 相机权限
                .permission(Permission.CAMERA)
                // 存储权限
                .permission(Permission.Group.STORAGE)

                .request(new OnPermission() {
                    @Override
                    public void hasPermission(List<String> granted, boolean isAll) {
                        //启动
                        start();
                    }

                    @Override
                    public void noPermission(List<String> denied, boolean quick) {
                        //启动
                        start();
                    }
                });

    }

    public void start() {
        Thread myThread = new Thread() {//创建子线程
            @Override
            public void run() {
                try {
                    sleep(500);//使程序休眠一秒
                    Intent it = new Intent(getApplicationContext(), LoginActivity.class);
//                    Intent it = new Intent(getApplicationContext(), Mian2Activity.class);
                    startActivity(it);
                    finish();//关闭当前活动
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        myThread.start();//启动线程
    }
}
